# Build recipe for angband
#
# Copyright 2018 Mateus P. Rodrigues <mprodrigues@dragora.org>.
#
# This recipe is free software, under the terms of the Apache License 2.0

program=angband
version=4.1.2
release=1

tarname=${program}-${version}.tar.gz

# Remote source(s)
fetch=http://rephial.org/downloads/4.1/$tarname

description="
Angband - Classic rogue-like game

Angband is one of the best known major rogue likes,
it is derived from Umoria and based on the writings
of J. R. R. Tolkien.
"

homepage=http://example.com
license=GPLv2

# Source documentation
docs="changes.txt copying.txt faq.txt readme.txt thanks.txt"
docsdir="${docdir}/${program}-${version}"

build()
{
    set -e

    unpack "${tardir}/$tarname"

    cd "$srcdir"

    ./autogen.sh
    ./configure CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --infodir=$infodir \
     --mandir=$mandir \
     --docdir=$docdir \
     --enable-curses \
     --enable-x11 \
     --enable-sdl \
     --build="$(cc -dumpmachine)"

    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 '{}' +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}${docsdir}"
    cp -p $docs "${destdir}${docsdir}"
}
